﻿using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ReporteadorCitas : System.Web.UI.Page
{
    private string rutaReporte;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            rutaReporte = ConfigurationManager.AppSettings.Get("rutaReportes");
            ReportDocument myReport = new ReportDocument();
            myReport.Load(Server.MapPath(rutaReporte + (string)Session["nombreReporte"]));
            //tambien se puede usar rutaReporte = HttpContext.Current.Server.MapPath("~/Reportes/");
          
            //
            // Creo el parametro y asigno el nombre
            //
            ParameterField param = new ParameterField();
            param.ParameterFieldName = "idCita";

            //
            // creo el valor que se asignara al parametro
            //
            ParameterDiscreteValue discreteValue = new ParameterDiscreteValue();
            discreteValue.Value = (string)Session["parametro"];
            param.CurrentValues.Add(discreteValue);

            //
            // Asigno el paramametro a la coleccion
            //
            ParameterFields paramFiels = new ParameterFields();
            paramFiels.Add(param);

            //
            // Asigno la coleccion de parametros al Crystal Viewer
            //
            CrystalReportViewer1.ParameterFieldInfo = paramFiels;
            Tables myTables = myReport.Database.Tables;
            ConnectionInfo myConnectionInfo = new ConnectionInfo();
            foreach (CrystalDecisions.CrystalReports.Engine.Table myTable in myTables)
            {
                TableLogOnInfo myTableLogonInfo = myTable.LogOnInfo;
                myConnectionInfo.ServerName = "localhost"; //Your server
                // <SQL servername>
                myConnectionInfo.DatabaseName = "veterinariaPAW"; //Leave DB Blank
                //// leave database name blank
                myConnectionInfo.UserID = "sa"; //Your User
                // username
                myConnectionInfo.Password = "123456a!"; //Your Users Password
                //password
      
                myTableLogonInfo.ConnectionInfo = myConnectionInfo;
                myTable.ApplyLogOnInfo(myTableLogonInfo);
            }


            //Reporte = myReport;
            CrystalReportViewer1.EnableDatabaseLogonPrompt = false;
            CrystalReportViewer1.ReportSource = myReport;
            CrystalReportViewer1.DataBind();
            CrystalReportViewer1.RefreshReport();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect((string)Session["URL"]);
    }
}
